# -*- coding: UTF-8 -*-
from django.contrib import admin
from django.utils.translation import gettext_lazy as _
from .models import DeviceCategory, Device, DeviceAttribute, KnifeAttribute


@admin.register(DeviceCategory)
class DeviceCategoryAdmin(admin.ModelAdmin):
    list_display = ['name', 'code', 'description', 'parent', 'created_at']
    list_display_links = ['name']
    search_fields = ['name', 'code', 'description']
    list_filter = ['parent', 'created_at']
    date_hierarchy = 'created_at'
    
    fieldsets = (
        (_('基本信息'), {
            'fields': ('name', 'code', 'description', 'parent')
        }),
    )


@admin.register(Device)
class DeviceAdmin(admin.ModelAdmin):
    list_display = ['name', 'code', 'category', 'status', 'location', 'purchase_date', 'warranty_date']
    list_display_links = ['name']
    search_fields = ['name', 'code', 'description']
    list_filter = ['category', 'status', 'location', 'purchase_date', 'warranty_date']
    date_hierarchy = 'purchase_date'
    
    fieldsets = (
        (_('基本信息'), {
            'fields': ('name', 'code', 'category', 'description', 'status')
        }),
        (_('位置信息'), {
            'fields': ('location',)
        }),
        (_('采购信息'), {
            'fields': ('purchase_date', 'warranty_date', 'purchase_price', 'supplier')
        }),
        (_('其他信息'), {
            'fields': ('note',),
            'classes': ('collapse',)
        }),
    )


@admin.register(DeviceAttribute)
class DeviceAttributeAdmin(admin.ModelAdmin):
    list_display = ['device', 'attribute', 'value', 'created_at']
    list_filter = ['attribute', 'created_at']
    search_fields = ['device__name', 'attribute__name', 'value']
    date_hierarchy = 'created_at'
    
    fieldsets = (
        (_('属性信息'), {
            'fields': ('device', 'attribute', 'value')
        }),
    )


@admin.register(KnifeAttribute)
class KnifeAttributeAdmin(admin.ModelAdmin):
    list_display = ['device', 'attribute', 'value', 'created_at']
    list_filter = ['attribute', 'created_at']
    search_fields = ['device__name', 'attribute__name', 'value']
    date_hierarchy = 'created_at'
    
    fieldsets = (
        (_('刀具属性'), {
            'fields': ('device', 'attribute', 'value')
        }),
    )